/**
 * @file ESDL_window.h
 */

#ifndef ESDL_window_h
#define ESDL_window_h

#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_image.h>
#include <stdbool.h>

#include "../graphics/sprite.h"
#include "../graphics/render.h"
#include "../graphics/draw.h"
#include "../devices/devices.h"
#include "../utils/list.h"
#include "events.h"

/**
 * @struct Window
 * @brief Window structure
 */
typedef struct EsdlWindow EsdlWindow;
struct EsdlWindow {
    SDL_Surface* screen; //!< @brief The main screen surface on which everithing is blitted. (it's a SDL element)
    EsdlSprite* sprite; //!< @brief This sprite is the first parent of all other sprite. It fill the window surface. @see Structure Sprite ; File ESDL_sprite.h
    EsdlMouse mouse; //!< @brief Mouse structure which provide some mouse informations @see Structure Mouse ; File ESDL_mouse.h
    EsdlKeyboard keyboard; //!< @brief Keyboard structure which provide keyboard informations @see Structure Keyboard ; File ESDL_keyboard.h
    EsdlRender render; //!< @brief Render structure which provide renderer informations see Structure Render ; File ESDL_render.h
    unsigned width; //!< @brief Width of the window @see Function openWindow()
    unsigned height; //!< @brief Height of the window @see Function openWindow()
    bool fullscreen; //!< @brief Fullscreen mode (true = fullscreen) @see Function fullScreen()
    int eventLoop; //!< @brief Event loop status (1: active ; 0: killed) @see Function startEventLoop() ; Function stopEventLoop()
    void* userData; //!< @brief UserData structure for saving user informations @see Function getUserData() ; Function setUserData()
};

extern EsdlWindow window; //!< External variable

//////////////////////////////////////////
///// Create and destroy SDL windows /////
//////////////////////////////////////////

/**
 * @brief Initialise SDL lib and create a window
 * @param char * title - The title of the window
 * @param int width - The width of the window
 * @param int height - The height of the window
 * @see closeWindow()
 */
void esdlCreateWindow(const char* title, unsigned width, unsigned height);

/**
 * @brief Close window
 * @see openWindow()
 */
void esdlCloseWindow();


/////////////////////////
///// Device getter /////
/////////////////////////

/**
 * @return The first parent sprite which represent the main screen of the window
 */
EsdlSprite* esdlGetScreen();

/**
 * @return The Keyboard structure
 * @see Structure Keyboard ; File ESDL_keyboard.h
 */
EsdlKeyboard* esdlGetKeyboard();

/**
 * @return The mouse structure
 * @see Structure Mouse ; File ESDL_mouse.h
 */
EsdlMouse* esdlGetMouse();

/**
 * @return The render structure
 * @see Structure Render ; File ESDL_render.h
 */
EsdlRender* esdlGetRender();


///// Other... /////

/**
 * @brief Set the title of the window
 * @param char* title - the title of the window
 */
void esdlSetWindowTitle(const char* title);

/**
 * @brief Get the title of the window
 * @param char** title - the title of the window
 */
void esdlGetWindowTitle(char** title);

/**
 * @brief Set a 32x32px sprite as the window icon
 * @param sprite - a 32x32px sprite
 */
bool esdlSetWindowIcon(const EsdlImage* image);

/**
 * @brief Turn the screen into window mode or fullscreen mode
 * @param bool fullscreen - Turn to fullscreen mode if true
 */
void esdlSetFullScreenMode(bool fullscreen);

/**
 * @brief Take a .bmp screenshot of the ESDL window
 * @param char * path - The path of the bmp file
 */
void esdlTakeScreenshot(const char* path);

/**
 * @return Return a void pointer on the user structure previously saved
 * @see setUserData()
 */
void* esdlGetUserData();

/**
 * @brief Save any user structure
 * @param void * data - A pointer on a structure create by the user
 * @see getUserData()
 */
void esdlSetUserData(void* data);

#endif
